<?php

class ContatoController extends Site_Controller_Action
{
    
    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        
        $this->view->headLink()->prependStylesheet($this->_urlbase.'/public/media/js/jquery-ui-1.10.2.custom/css/custom-theme/jquery-ui-1.10.2.custom.css'); 
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/jquery-ui-1.10.2.custom/js/jquery-1.9.1.min.js');
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/jquery-ui-1.10.2.custom/js/jquery-ui-1.10.2.custom.min.js');
        
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/validation/dist/jquery.validate.min.js');
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/view/contato.js?1=2');
        
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/jquery.maskMoney.min.js');
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/jquery.maskedinput.min.js');
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/mask.js');
        
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/mapa.js?1='.rand(99,9999));
        
        $sessao = new Zend_Session_Namespace('Parametros');
        $this->view->parametros  = $sessao->parametros;
        
        if ($this->getRequest()->isPost()) {
            try {
                $formData = $this->getRequest()->getPost();

                Zend_Loader::loadClass('envioemail','library');

                $arr['nome'] = $formData['nome'];
                $arr['email'] = $formData['email'];
                $arr['telefone'] = $formData['telefone'];
                $arr['assunto'] = $formData['assunto'];
                $arr['mensagem'] = $formData['mensagem'];
                $arr['urlbase']  = $this->_urlbase;

                $ok = envioemail::formularioContato($arr);

                if($ok){
                    echo "<script>alert('Mensagem enviada com sucesso!');</script>";
                }
                
            } catch (Exception $exc) {
                //echo 'error: '.$exc->getMessage();
            }
        }
    }
}

